import Vue from "vue";
import VueRouter from "vue-router";


Vue.use(VueRouter);
// 路由跳转重定向报错配置
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// 路由配置
const routes = [
  {path:'/',redirect:{name:'home'}},
  {path:'/home',name:'home',component:()=>import('../views/home/index.vue')},
  {path:'/category',name:'category',component:()=>import('../views/catetory/index.vue')},
  {path:'/suprise',name:'suprise',component:()=>import('../views/suprise/index.vue')},
  {path:'/cart',name:'cart',component:()=>import('../views/cart/index.vue')},
  {path:'/my/:uid',name:'my',component:()=>import('../views/my/index.vue'),
  beforeEnter: (to, from, next) => {
    // ...
    var token = localStorage.token;
    var uid = localStorage.uid
    console.log(to)
    console.log(from)
    if(token&&uid){
      next()
    }else{
      next('/login')
    }
  }
},
  {path:'/info/:goodid',name:'info',component:()=>import('../views/info/index.vue'),
  // afterEach:(to,from)=>{
  //   if(from.name == "/info"){
  //     Vue.destroyed
  //   }
  // }
},
  {path:'/login',name:'login',component:()=>import('../components/login.vue'),
  // beforeEnter: (to, from, next) => {
  //   // ...
  //   if(from.name == "/"&&from.name == "/home"&&from.name == "/category"&&from.name == "/suprise"&&from.name == "/my"&&from.name == "/cart"){
  //     next()
  //   }else{
  //     alert("hahah ")
  //   }
  // }
},
 
];

const router = new VueRouter({
  routes
});

export default router;
